const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nyinit: 0,
    orderStr:'desc',
    istype:1,
    id:'',
    dateNo:"",
    orderData:[]
  },
  fromaTimes(date, formatNumber) {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    console.log(year, month);
    if (this.data.nyinit == 0) {
      return year + '-' + (month<10?('0'+month):month)
    } else {
      return year+''
    }
    // return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
  },
  orderStrHeld(){
    if (this.data.orderStr == 'desc') {
      this.setData({
        orderStr: 'asc',
      })
    } else {
      this.setData({
        orderStr: 'desc',
      })
    }
    this.getList()
  },
  getList() {
    let that = this
    let newData={}
    wx.showLoading({
      title: '',
      mask:true
    })
    newData.orderStr = that.data.orderStr
    // if(that.data.nyinit==1){
    //   newData.year = that.data.dateNo
    // }else{
    //   newData.yearAndMonth = that.data.dateNo
    // }
    wx.request({
      url: app.globalData.serverUrlgdb + '/statistics/count/availableNum/rank',
      method: 'POST',
      header: {
        'token': wx.getStorageSync('token')
      },
      data: newData,
      success: (res => {
        let resData = res.data
        if (resData.code == 200) {
          that.setData({
            orderData: resData.data.availableNumRankList
          })
          wx.hideLoading()
        }else{
          wx.hideLoading()
        }
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id:options.id,
      dateNo:this.fromaTimes(new Date())
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      orderStr: 'desc',
    })
    this.getList()
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})